import Vue from 'vue'
import App from './App.vue'
import './registerServiceWorker'
import router from './router'
import store from './store'

import ElementUI, {Message} from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';

Vue.use(ElementUI);

import axios from 'axios'
import VueAxios from 'vue-axios'

Vue.use(VueAxios, axios)

Vue.config.productionTip = false
Vue.prototype.$shopHost = 'http://localhost:8200/'

//添加请求拦截器
axios.interceptors.request.use(function (config){
  //在发送请求之前做些什么
  // @ts-ignore
  config.headers['token']=localStorage.getItem("token");
  return config;
},function (error){
  //对请求错误做点什么
  return Promise.reject(error);
});

//添加响应拦截器
axios.interceptors.response.use(function (response){
  //2xx范围内的状态码都会触发该函数
  //对响应数据做点什么
  return response;
},function (error){
  //2xx范围内的状态码都会触发该函数
  if (error.response.status == 412) {
    Message.error("用户未登录");
    router.push('/');
  }
  //对响应数据做点什么
  return Promise.reject(error);
});

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
